// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

import './plugins/element'
// 引入全局样式表
import './assets/css/global.css'
import "element-ui/lib/theme-chalk/index.css"; //导入element样式
import './assets/fonts/iconfont.css'  //引入第三方阿里图标库
import TreeTable from 'vue-table-with-tree-grid' //引入table-with-tree-grid组件

import VueQuillEditor from 'vue-quill-editor' // 导入编辑器
// require styles 导入富文本编辑器样式css
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
//导入进度条nprogress js+css文件
import NProgress from "nprogress";  
import "nprogress/nprogress.css";

// 配置请求axios
import axios from "axios";
import {config} from "shelljs";

Vue.prototype.$http = axios
axios.defaults.baseURL = 'http://www.tangxiaoyang.vip:8888/api/v2/'
// axios.defaults.baseURL = 'http://shop.tangxiaoyang.vip:8888/api/v2/'

// 通过axios请求拦在器添加 token，每一次的发送请求前都携带token

// ***在request拦截器中展示进度条nprogress   是 NProgress.start()函数
axios.interceptors.request.use(config => {
  NProgress.start()   //启动进度条
  // console.log(config)
  config.headers.Authorization = window.sessionStorage.getItem('token')

  // 在后必须加 return config
  return config
})

//全部导入
import _ from 'lodash'
//只导入需要的模块
import cloneDeep from "lodash/cloneDeep";

// ***在response拦截器中关闭进度条nprogress  是 NProgress.done()函数
axios.interceptors.request.use(config =>{
  NProgress.done()  //关闭进度条
  return config
})


// 挂载到vue原型上
Vue.prototype._ = _  //全部导入的挂载方式
Vue.prototype.cloneDeep = cloneDeep //导入某个功能的挂载方式


Vue.config.productionTip = false
// 注册组件table-with-tree-grid
Vue.component('tree-table', TreeTable)
Vue.use(VueQuillEditor); //将富文本编辑器组件全局注册


// 为了时间戳转换正常的格式-需要注册全局时间过滤器
Vue.filter('dataFormat', function (originVal) {
  const dt = new Date(originVal)

  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDay() + '').padStart(2, '0')

  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')

  // return `yyyy-mm-dd hh:mm:ss`
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {App},
  template: '<App/>'
})
